package com.starview.star.compiler.operator;

import com.starview.star.compiler.util.PrettyPrintDisplay;
import com.starview.star.compiler.util.PrettyPrintable;

@SuppressWarnings("serial")
public abstract class Operator implements PrettyPrintable
{
  private final int priority;
  private final int minPriority;
  private final String operator;
  private final OperatorForm form;

  public Operator(String operator, int priority, OperatorForm form)
  {
    this(operator, form, priority, 0);
  }

  public Operator(String operator, OperatorForm form, int priority, int minPriority)
  {
    assert form != null;
    this.priority = priority;
    this.minPriority = minPriority;
    this.form = form;
    this.operator = operator;
  }

  public String getOperator()
  {
    return operator;
  }

  public OperatorForm getForm()
  {
    return form;
  }

  public int getPriority()
  {
    return priority;
  }

  public int getMinPriority()
  {
    return minPriority;
  }

  @Override
  public String toString()
  {
    return PrettyPrintDisplay.toString(this);
  }

  @Override
  public int hashCode()
  {
    return ((operator.hashCode() * 37 + priority) * 37 + minPriority) * 37 + form.hashCode();
  }

  @Override
  public boolean equals(Object obj)
  {
    if (obj instanceof Operator) {
      Operator other = (Operator) obj;

      return operator.equals(other.operator) && other.priority == priority && other.minPriority == minPriority
          && form == other.form;
    }
    return false;
  }

  public abstract boolean dominatesRight(Operator op);

  public abstract boolean dominatesLeft(Operator op);

  public abstract String toLatex();
}
